<template>
  <a-card :bordered="false">
    <van-search placeholder="请选择条件查询" readonly @click="showSearchPopup" style="margin-top: -10px;width: 100%;padding: 0px;margin-bottom: 10px"/>
    <a-button type="primary" @click="searchReset" icon="reload" style="width: 100%;margin-bottom: 10px">重置</a-button>

    <!-- table区域-begin -->
    <div>
      <div class="list">
        <van-list
          v-model="loading"
          :finished="finished"
          offset="100"
          finished-text="没有更多了"
          @load="onLoadList"
          :immediate-check="false"
        >
          <div
            class="customer-list"
            v-for="(item,i) in dataSource"
            :key="i"
          >
            <div>
              <div class="name">付款单编号：{{ item.remitNo || '无' }}</div>
              <div class="contact">
                <span>入库单编号：{{ item.inDepositoryNo || '无' }}</span>
              </div>
              <div class="contact">
                <span>付款时间：{{ item.createTime || '无' }}</span>
              </div>
              <div class="contact">
                <span>供应商：{{ item.supplierName || '无' }}</span>
                <span style="float: right">
                  <a @click.stop="downloadAnnex(item.annex)" v-if="item.annex != null">查看附件</a>
                  <a-divider type="vertical" v-if="item.annex != null"/>
                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(item.id)">
                    <a @click.stop="">删除</a>
                  </a-popconfirm>
                </span>
              </div>
              <div class="contact">
                <span>付款账户：{{ item.remitAccount || '无' }}</span>
                <span style="margin-left: 20px">付款人：{{ item.remitPeople || '无' }}</span>
              </div>
              <div class="contact">
                <span>付款金额：{{ item.remitMoney || 0 }}</span>
                <span style="margin-left: 20px;margin-right: 20px">实际付款金额：{{ item.realityRemitMoney || 0 }}</span>
              </div>
              <div class="contact">
                <span>付款备注：{{ item.remitRemark || '无' }}</span>
              </div>
            </div>
          </div>
        </van-list>
      </div>

      <!--<a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <a slot="inDepositoryNo" @click="inDepositoryOrderDetail(text)" slot-scope="text,record">{{ text }}</a>

        <span slot="annex" slot-scope="text,record">
          <a v-if="text != null" @click="downloadAnnex(text)">下载</a>
          <span v-if="text==null">无</span>
        </span>


        <span slot="action" slot-scope="text, record">
          &lt;!&ndash;<a @click="printRemit(record)">打印</a>
          <a-divider type="vertical" />&ndash;&gt;
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>-->
    </div>
    <van-popup v-model="showSearchPopupFlag" position="top" >
      <a-card :bordered="false">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <div>付款时间：
            <a-input @click="remitDate.show = true" v-model="remitDate.text" readOnly style="text-align: center;"></a-input>
            <van-popup v-model="remitDate.show" round position="bottom">
              <van-picker
                show-toolbar
                title="请选择时间"
                :columns="remitDateList"
                value-key="itemText"
                @cancel="remitDate.show = false"
                @confirm="changeRemitDate" />
            </van-popup>
          </div>
          <div style="margin-top: 5px">付款人：
            <van-dropdown-menu>
              <van-dropdown-item v-model="remitPeople" :options="userOption" @change="changeRemitPeople"/>
            </van-dropdown-menu>
          </div>
          <a-row :gutter="24" style="margin-bottom: 10px;margin-top: 10px">
            <a-col :span="12">
              <a-button type="primary" style="width: 100%" @click="searchQuery" icon="search">查询</a-button>
            </a-col>
            <a-col :span="12">
              <a-button type="primary" @click="searchReset" icon="reload" style="width: 100%">重置</a-button>
            </a-col>
          </a-row>
        </a-form>
      </a-card>
    </van-popup>

    <in-depository-order-detail-modal ref="inDepositoryOrderDetailModal"></in-depository-order-detail-modal>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import inDepositoryOrderDetailModal
    from "../../supplychain/purchaseInDepositoryOrder/modules/inDepositoryOrderDetailModal";
  import {deleteAction, getAction} from "../../../../api/manage";

  export default {
    name: 'purchaseRemitList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      inDepositoryOrderDetailModal,
    },
    data () {
      return {
        description: '采购付款单管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'付款单编号',
            align:"center",
            dataIndex: 'remitNo'
          },
          {
            title:'入库单编号',
            align:"center",
            dataIndex: 'inDepositoryNo',
            slots: { title: 'customTitle' },
            scopedSlots: { customRender: 'inDepositoryNo' },
          },
          {
            title:'付款时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'供应商名称',
            align:"center",
            dataIndex: 'supplierName'
          },
          {
            title:'付款金额',
            align:"center",
            dataIndex: 'remitMoney'
          },
          {
            title:'实际付款金额',
            align:"center",
            dataIndex: 'realityRemitMoney'
          },
          {
            title:'付款账户',
            align:"center",
            dataIndex: 'remitAccount'
          },
          {
            title:'付款人',
            align:"center",
            dataIndex: 'remitPeople'
          },
          {
            title:'付款备注',
            align:"center",
            dataIndex: 'remitRemark'
          },
          {
            title:'附件',
            align:"center",
            dataIndex: 'annex',
            slots: { title: 'customTitle' },
            scopedSlots: { customRender: 'annex' },
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },
        url: {
          list: "/GhFinancePurchaseRemitOrder/list",
          delete: "/GhFinancePurchaseRemitOrder/delete",
          deleteBatch: "/GhFinancePurchaseRemitOrder/deleteBatch",
          getSearchConditionData: "/GhFinancePurchaseRemitOrder/getQueryCriteriaData",
          queryUserList: "/erp/user/selectUserByDepartId",
          queryDepartTreeList: "/erp/user/selectDepartTreeList",
          queryPurchaseOrder: "/GhFinancePurchaseRemitOrder/queryPurchaseByOrderNo"
        },
        dictOptions:{},
        superFieldList:[],
        remitPeopleData:[],  //付款人员列表
        remitDateList:[],  //搜索条件：付款时间
        currentRemitDate:"",  //当前付款时间
        currentKey: false,
        startDate: '',
        endDate: '',
        dateValue: [],
        /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
        queryParam: {},
        dataFields: {
          title: 'departName',
          key: 'id',
          value: 'id',
          children: "children"
        },
        currentDepartId: "",  //当前所选部门
        departListData:[],    //部门列表
        finished: false,
        showSearchPopupFlag: false,
        remitDate:{
          show:false,
          text:'全部',
        },
        userOption: [
          {text:'全部',value:""}
        ],
        remitPeople:""
      }
    },
    created() {
      this.initSearchConditionData();
      this.loadUserListData();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      showSearchPopup(){
        this.showSearchPopupFlag = true
      },
      //详情
      inDepositoryOrderDetail(value){
        this.$refs.inDepositoryOrderDetailModal.title = "采购入库订单详情";
        getAction(this.url.queryPurchaseOrder,{orderNo:value}).then((res) => {
          if (res.success){
            var obj = res.result.records||res.result;
            this.$refs.inDepositoryOrderDetailModal.showDetail(obj);
          }else {
            this.$message.error(res.message)
          }
        })
      },
      //打印
      printRemit(record){

      },
      //加载用户列表
      loadUserListData() {
        getAction(this.url.queryUserList).then((res) => {
          if (res.success) {
            this.remitPeopleData = res.result.records||res.result;
            for (let i=0;i<this.remitPeopleData.length;i++){
              this.userOption.push({
                text: this.remitPeopleData[i].realname,
                value: this.remitPeopleData[i].realname
              })
            }
          }
        })
      },
      initSearchConditionData() {
        getAction(this.url.getSearchConditionData).then(res => {
          if (res.success) {
            this.remitDateList = res.result.remitDateList;
          }
        })
      },
      filterOptionRemitPeople(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      onLoadList(e){
        this.ipagination.current++
        this.loadData(this.ipagination.current)
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
          this.dataSource = []
          this.finished = false;
        }
        var params = this.getQueryParams();//查询条件

        if (this.currentRemitDate != null && this.currentRemitDate != '') {
          params.currentRemitDate = this.currentRemitDate;
        }else {
          params.currentRemitDate = "";
        }
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = [...this.dataSource, ...res.result.records]
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
          if(res.result.records.length<10){
            this.finished = true;
          }
        }).finally(() => {
          this.loading = false
        })
      },
      downloadAnnex(value){
        window.location.href = value + '?response-content-type=application/octet-stream';
      },
      changeRemitDate(e){
        this.remitDate.text = e.itemText
        this.remitDate.show = false
        const { key, itemValue, itemText } = e
        this.currentRemitDate = itemValue
        let obj = {
          key,
          itemValue,
          itemText
        }
        this.loadData(1)
        this.showSearchPopupFlag = false
      },
      changeRemitPeople(value) {
        this.showSearchPopupFlag = false
        this.queryParam.remitPeople = value;
        this.loadData(1)
      },
      searchQuery(){
        this.loadData(1);
        this.selectedRowKeys = []
        this.selectedRows = []
        this.showSearchPopupFlag = false
      },
      searchReset() {
        this.remitPeople = ""
        this.currentRemitDate = ""
        this.remitDate.text = "全部"
        this.queryParam = {}
        this.selectedRowKeys = []
        this.selectedRows = []
        this.showSearchPopupFlag = false
        this.loadData(1);
      },
      handleDelete(id) {
        if(!this.url.delete){
          this.$message.error("请设置url.delete属性!")
          return
        }
        let that = this;
        that.loading = true;
        deleteAction(that.url.delete, {id: id}).then((res) => {
          if (res.success) {
            //重新计算分页问题
            that.$message.success(res.message);
            that.loadData(1);
          } else {
            that.$message.warning(res.message);
          }
        }).finally(() => {
          this.loading = false
        });
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';

  /deep/ .van-dropdown-menu__bar{
    height: 30px;
    box-shadow: none;
    border: 1px solid lightgrey;
    border-radius: 5px;
  }

  .list{
    overflow-y: scroll;
    height:100vh;
  }
  ::-webkit-scrollbar {
    display: none;
  }
  .customer-list {
    align-items: center;
    border-top: 1px solid #d9d9d9;
    /*height: 120px;*/
  }
  .name{
    margin-top: 10px;
    margin-bottom: 5px;
    font-size: 13px;
    color: #161616;
    line-height: normal;
  }
  .contact{
    font-size: 12px;
    color: #a39f9f;
    margin-bottom: 5px;
  }
</style>